<!-- 代办任务 -->
<template>
  <div class='payment_task_agency'>
    <dt-search ref="search" :labelWidth="100" @reset="resetFun">
      <Button type="primary" @click="exportTable(0)" v-if="unlocking('0106020100')"
        style="margin-right:8px;">导出</Button>
      <Button type="primary" @click="exportTable(1)"
        v-if="unlocking('0106020300')">全号导出</Button>
    </dt-search>
    <dt-grid ref="table" :page="page" :onFetch='onFetch' />
    <!-- 客户详情 -->
    <Modal v-model="detailsFlag" title="客户详情" width="80%" :styles="{top:'5%'}"
      :footer-hide="true">
      <detail-page v-if="detailsFlag" :detailsParams="detailsParams"></detail-page>
    </Modal>
    <!-- 代回款弹窗 -->
    <Modal v-model="paymentTaskFlag" title="新增回款" @on-cancel="AllModalCancel" width="700px"
      :footerHide="true">
      <payment-task-modal @onClose='AllModalCancel' :taskPrimaryKey='taskPrimaryKey'
        @onChangeTable='onSuccess' v-if="paymentTaskFlag" />
    </Modal>
  </div>
</template>

<script>
  import searchOpt from '../../opt/taskAgencysearch'
  import paymentMgr from '@/biz/paymenManage/paymentTask'
  import paymentTaskModal from './paymentTaskModal.vue'
  import column from './paymentTaskagency'
  import detailPage from '../../../allCustomersManagement/details.vue'
  import dt from '@dt/dt'

  export default {
    components: {
      paymentTaskModal,
      detailPage
    },
    props: {},
    data() {
      return {
        paymentTaskFlag: false,
        searchInfo: {
          status: '',
          receiptType: '',
          contractCode: '',
          productId: '',
          buildingId: '',
          unitId: '',
          roomCode: '',
          housesId: dt.buildInfo().housesId,
          taskType: 1 //任务类型 1待完成 2.已完成
        },
        detailsFlag: false,
        detailsParams: {},
        filterParams: {},
        page: {
          current: 1
        },
        columns: null,
        taskPrimaryKey: '',
      }
    },

    methods: {
      resetFun() {
        this.$refs.search.init(this.$refs.table, searchOpt.options(this), this
          .searchInfo)
      },
      onFetch(data) {
        this.filterParams = {
          ...data
        }
        return paymentMgr.listInfo(data).then(res => {
          return res
        }).catch(err => {})
      },
      //导出
      exportTable(exportType) {
        let params = { ...this.filterParams }
        params.exportType = exportType
        paymentMgr.exportTaskList(params)
      },
      // 保留列表查询参数
      retainParamsFun() {
        let params = Object.assign({
          paymentShowTab: 'paymentTaskagency',
          filter: this.$refs.table.throwFilter().export()
        }, this.filterParams)
        dt.memory.set('payment_params', params)
      },
      //查看
      viewFun(row) {
        console.log(row, '@@@@@')
        if (!this.unlocking('0104030300')) {
          return false
        } else {
          this.retainParamsFun()
          this.$router.push({
            name: 'contractDetail',
            query: {
              examineBtn: false,
              showTab: 'payment',
              orderStatusName: '签约',
              orderNum: row.contractCode, // 单号
              businessId: row.contractId, // 业务id
              subscriptionId: row.subscriptionId, //认购ID
            },
          })
        }
      },
      // 客户姓名链接到客户资料
      onLinkUser(row) {
        if (row.customerName == '-') {
          return false
        }
        this.detailsFlag = true
        this.detailsParams = {
          customerId: row.customerId, // 手机号唯一编码
          userCustomerId: row.userCustomerId, // 客户信息唯一编码
          buildingId: dt.buildInfo().housesId,
          userId: dt.userInfo().userId,
          cityCode: dt.buildInfo().cityId,
        }
      },
      //待回款
      paymentTaskBtn(row) {
        this.paymentTaskFlag = true
        this.taskPrimaryKey = row.taskPrimaryKey
      },
      AllModalCancel() {
        this.paymentTaskFlag = false
      },
      onSuccess() {
        this.$refs.table.fetch()
      },
    },
    created() {},
    mounted() {
      let _this = this

      let retainParams = dt.memory.get('payment_params')

      this.$refs.table.init(this, new column(this), { ...retainParams })
      this.$refs.search.init(this.$refs.table, searchOpt.options(this), this
        .searchInfo)
      this.$refs.table.fetch()

      // 首页跳转
      if (Object.keys(this.$route.params).length) {
        this.searchInfo.status = String(this.$route.params.status)
      }
      if (retainParams) {
        Object.keys(this.searchInfo).map(function(key) {
          retainParams[key] && (_this.searchInfo[key] = retainParams[key]) //比较key
        })
        retainParams.rows && (this.page.rows = retainParams.rows)
        retainParams.page && (this.page.current = retainParams.page)
      }
      this.$nextTick(function() {
        if (retainParams)
          retainParams.filter && _this.$refs.table.throwFilter().import(retainParams
            .filter)
      })
    },
  }
</script>
<style lang='scss' scoped>
  .total_row {
    margin: 20px 0;

    .total_num_text {
      padding-left: 8px;
      font-size: 16px;
      line-height: 32px;
    }
  }

  .payment_arrival_btn {
    width: 100px;
    margin-left: 10px;
  }
</style>